import request from '@/utils/request.js'
/**
 * 根据频道id和时间戳获取文章列表
 * @param {*} channelId 频道编号
 * @param {*} timestamp 时间戳
 */
export const getArticles = (channelId, timestamp) => {
  const t = request({
    method: 'GET',
    url: '/app/v1_1/articles',
    params: {
      channel_id: channelId,
      timestamp: timestamp, // 时间戳，请求新的推荐数据传当前的时间戳，请求历史推荐传指定的时间戳
      with_top: 1
    }
  })
  console.log('getChannels:', t)
  return t
}

export const unLike = (articleId) => {
  // eslint-disable-next-line no-undef
  return request({
    url: '/app/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: articleId
    }
  })
}

export const report = (articleId, reportType) => {
  return request({
    method: 'POST',
    url: '/app/v1_0/article/reports',
    data: {
      target: articleId,
      type: reportType
    }
  })
}

/**
 * 获取文章详情
 * @param {*} articleId
 */
export const getDetail = articleId => {
  return request({
    method: 'GET',
    url: '/app/v1_0/articles/' + articleId
  })
}

/**
 * 点赞文章
 * @param {*} id 添加文章的编号
 * @returns
 */
export const addLike = id => {
  return request({
    method: 'POST',
    url: '/app/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消点赞
 * @param {*} id 添加文章的id
 * @returns
 */
export const delLike = id => {
  return request({
    method: 'DELETE',
    url: '/app/v1_0/article/likings/' + id
  })
}

/**
 * 对文章不喜欢
 * @param {*} id 不喜欢文章的id
 * @returns
 */
export const noLike = id => {
  return request({
    method: 'POST',
    url: '/app/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

/**
 * 取消对文章的不喜欢
 * @param {*} id 不喜欢文章的id
 * @returns
 */
export const notNolike = id => {
  return request({
    method: 'DELETE',
    url: '/app/v1_0/article/dislikes/' + id
  })
}
